package SnakeGame;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author HOME
 */
public class Ferramentas {
    
    public static void paintImage(Graphics g,Image img ,int x,int y,int ix,int iy,int w,int h)
	{
		g.setClip(x,y,w,h);
		g.drawImage(img,x-ix,y-iy,0);
		g.setClip(0,0,500,500);
	}
	
	public static byte[] toByte(int n)
	{
		byte[] r=null;
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		DataOutputStream dos=new DataOutputStream(bos);
		try {
			dos.writeInt(n);
			r=bos.toByteArray();
			dos.close();
			bos.close();
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		return r;
	}
	public static int toInt(byte[] b)
	{
		int r=0;
		ByteArrayInputStream bis=new ByteArrayInputStream(b);
		DataInputStream dis=new DataInputStream(bis);
		try {
			r=dis.readInt();
			dis.close();
			bis.close();
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		return r;
	}
    
}
